using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VKALENDER
    {
        public DataRow Convert2KALENDER(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryKALENDER(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["AKKMANDANT"] = " ".PadRight(2 ); 
         dwReturn["AKKWERK"] = " ".PadRight(3 ); 
         dwReturn["AKKJJJJ"] = " ".PadRight(4 ); 
         dwReturn["AKKMM"] = " ".PadRight(2 ); 
         dwReturn["AKKANZTAG"] = " ".PadRight(2 ); 
         dwReturn["AKKTAGFREI01"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI02"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI03"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI04"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI05"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI06"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI07"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI08"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI09"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI10"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI11"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI12"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI13"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI14"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI15"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI16"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI17"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI18"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI19"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI20"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI21"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI22"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI23"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI24"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI25"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI26"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI27"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI28"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI29"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI30"] = " ".PadRight(1 ); 
         dwReturn["AKKTAGFREI31"] = " ".PadRight(1 ); 
         dwReturn["AKKAENDZL"] = " ".PadRight(0 ); 
         dwReturn["AKKAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["AKKAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["AKKNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["AKKNEUDAT"] = " ".PadRight(0 ); 
         dwReturn["AKKFILLER"] = " ".PadRight(30 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapKALENDER(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveKALENDER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryKALENDER(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapKALENDER(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertKALENDER(dwLocal, ITXDBVERSION);
            }
            UpdateKALENDER(dwLocal);
        }
        public void InsertKALENDER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO KALENDER(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryKALENDER(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM KALENDER WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM KALENDER  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "KALENDER";
            Return = Result;
            return Return;
        }
        public void DeleteKALENDER(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM KALENDER   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateKALENDER(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE KALENDER SET "
                    +"AKKMANDANT= :AKKMANDANT,"
                    +"AKKWERK= :AKKWERK,"
                    +"AKKJJJJ= :AKKJJJJ,"
                    +"AKKMM= :AKKMM,"
                    +"AKKANZTAG= :AKKANZTAG,"
                    +"AKKTAGFREI01= :AKKTAGFREI01,"
                    +"AKKTAGFREI02= :AKKTAGFREI02,"
                    +"AKKTAGFREI03= :AKKTAGFREI03,"
                    +"AKKTAGFREI04= :AKKTAGFREI04,"
                    +"AKKTAGFREI05= :AKKTAGFREI05,"
                    +"AKKTAGFREI06= :AKKTAGFREI06,"
                    +"AKKTAGFREI07= :AKKTAGFREI07,"
                    +"AKKTAGFREI08= :AKKTAGFREI08,"
                    +"AKKTAGFREI09= :AKKTAGFREI09,"
                    +"AKKTAGFREI10= :AKKTAGFREI10,"
                    +"AKKTAGFREI11= :AKKTAGFREI11,"
                    +"AKKTAGFREI12= :AKKTAGFREI12,"
                    +"AKKTAGFREI13= :AKKTAGFREI13,"
                    +"AKKTAGFREI14= :AKKTAGFREI14,"
                    +"AKKTAGFREI15= :AKKTAGFREI15,"
                    +"AKKTAGFREI16= :AKKTAGFREI16,"
                    +"AKKTAGFREI17= :AKKTAGFREI17,"
                    +"AKKTAGFREI18= :AKKTAGFREI18,"
                    +"AKKTAGFREI19= :AKKTAGFREI19,"
                    +"AKKTAGFREI20= :AKKTAGFREI20,"
                    +"AKKTAGFREI21= :AKKTAGFREI21,"
                    +"AKKTAGFREI22= :AKKTAGFREI22,"
                    +"AKKTAGFREI23= :AKKTAGFREI23,"
                    +"AKKTAGFREI24= :AKKTAGFREI24,"
                    +"AKKTAGFREI25= :AKKTAGFREI25,"
                    +"AKKTAGFREI26= :AKKTAGFREI26,"
                    +"AKKTAGFREI27= :AKKTAGFREI27,"
                    +"AKKTAGFREI28= :AKKTAGFREI28,"
                    +"AKKTAGFREI29= :AKKTAGFREI29,"
                    +"AKKTAGFREI30= :AKKTAGFREI30,"
                    +"AKKTAGFREI31= :AKKTAGFREI31,"
                    +"AKKAENDZL= :AKKAENDZL,"
                    +"AKKAENDBEN= :AKKAENDBEN,"
                    +"AKKAENDDAT= :AKKAENDDAT,"
                    +"AKKNEUBEN= :AKKNEUBEN,"
                    +"AKKNEUDAT= :AKKNEUDAT,"
                    +"AKKFILLER= :AKKFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("AKKMANDANT", OracleType.NVarChar).Value = dwData["AKKMANDANT"].ToString(); 
          or1.Parameters.Add("AKKWERK", OracleType.NVarChar).Value = dwData["AKKWERK"].ToString(); 
          or1.Parameters.Add("AKKJJJJ", OracleType.NVarChar).Value = dwData["AKKJJJJ"].ToString(); 
          or1.Parameters.Add("AKKMM", OracleType.NVarChar).Value = dwData["AKKMM"].ToString(); 
          or1.Parameters.Add("AKKANZTAG", OracleType.NVarChar).Value = dwData["AKKANZTAG"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI01", OracleType.NVarChar).Value = dwData["AKKTAGFREI01"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI02", OracleType.NVarChar).Value = dwData["AKKTAGFREI02"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI03", OracleType.NVarChar).Value = dwData["AKKTAGFREI03"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI04", OracleType.NVarChar).Value = dwData["AKKTAGFREI04"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI05", OracleType.NVarChar).Value = dwData["AKKTAGFREI05"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI06", OracleType.NVarChar).Value = dwData["AKKTAGFREI06"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI07", OracleType.NVarChar).Value = dwData["AKKTAGFREI07"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI08", OracleType.NVarChar).Value = dwData["AKKTAGFREI08"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI09", OracleType.NVarChar).Value = dwData["AKKTAGFREI09"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI10", OracleType.NVarChar).Value = dwData["AKKTAGFREI10"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI11", OracleType.NVarChar).Value = dwData["AKKTAGFREI11"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI12", OracleType.NVarChar).Value = dwData["AKKTAGFREI12"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI13", OracleType.NVarChar).Value = dwData["AKKTAGFREI13"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI14", OracleType.NVarChar).Value = dwData["AKKTAGFREI14"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI15", OracleType.NVarChar).Value = dwData["AKKTAGFREI15"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI16", OracleType.NVarChar).Value = dwData["AKKTAGFREI16"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI17", OracleType.NVarChar).Value = dwData["AKKTAGFREI17"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI18", OracleType.NVarChar).Value = dwData["AKKTAGFREI18"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI19", OracleType.NVarChar).Value = dwData["AKKTAGFREI19"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI20", OracleType.NVarChar).Value = dwData["AKKTAGFREI20"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI21", OracleType.NVarChar).Value = dwData["AKKTAGFREI21"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI22", OracleType.NVarChar).Value = dwData["AKKTAGFREI22"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI23", OracleType.NVarChar).Value = dwData["AKKTAGFREI23"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI24", OracleType.NVarChar).Value = dwData["AKKTAGFREI24"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI25", OracleType.NVarChar).Value = dwData["AKKTAGFREI25"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI26", OracleType.NVarChar).Value = dwData["AKKTAGFREI26"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI27", OracleType.NVarChar).Value = dwData["AKKTAGFREI27"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI28", OracleType.NVarChar).Value = dwData["AKKTAGFREI28"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI29", OracleType.NVarChar).Value = dwData["AKKTAGFREI29"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI30", OracleType.NVarChar).Value = dwData["AKKTAGFREI30"].ToString(); 
          or1.Parameters.Add("AKKTAGFREI31", OracleType.NVarChar).Value = dwData["AKKTAGFREI31"].ToString(); 
          or1.Parameters.Add("AKKAENDZL", OracleType.NVarChar).Value = dwData["AKKAENDZL"].ToString(); 
          or1.Parameters.Add("AKKAENDBEN", OracleType.NVarChar).Value = dwData["AKKAENDBEN"].ToString(); 
          or1.Parameters.Add("AKKAENDDAT", OracleType.NVarChar).Value = dwData["AKKAENDDAT"].ToString(); 
          or1.Parameters.Add("AKKNEUBEN", OracleType.NVarChar).Value = dwData["AKKNEUBEN"].ToString(); 
          or1.Parameters.Add("AKKNEUDAT", OracleType.NVarChar).Value = dwData["AKKNEUDAT"].ToString(); 
          or1.Parameters.Add("AKKFILLER", OracleType.NVarChar).Value = dwData["AKKFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
